export const webList = (self, tiyData) => {
  self.$Spin.show();
  tiyData.tData.productList.splice(0,tiyData.tData.productList.length );
  self.$apiProduct.getProductClassifications({
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage,
    "productCode": tiyData.tParam.productCode,
    "productName": tiyData.tParam.productName,
    "selectedClassification": tiyData.tParam.selectedClassification,
    "operation": tiyData.tParam.operation,
    "sort": tiyData.tParam.orderBy,
    "state": tiyData.tParam.state
  })
    .then(function (response) {
      self.$Spin.hide();
      if (response.success) {
        tiyData.tParam.length = [];
        let productPage = response.result;
        tiyData.tPage.total = productPage.total;
        tiyData.tPage.stepNumber = productPage.pageSize;
        productPage.list.forEach(
          function (item) {
            tiyData.tData.productList.push(item);
          }
        );
      } else {
        self.$Spin.hide();
        self.$Message.error(response.errorMessage);
      }
    });

};

export const batchOperation = (self, tiyData) =>{
  self.loadingData = true;
  self.$Spin.show();

  let productIds=[];
  tiyData.tParam.selection.forEach(
    function(selected,index){
      productIds.push(selected.id)
    }
  )
  if(tiyData.tParam.operation==0){
    self.$apiProduct.batchInsertProductClassification({
      "productIds": productIds.toString(),
      "selectedClassification": tiyData.tParam.selectedClassification,
      "operation": tiyData.tParam.operation,
    })
      .then(function (response) {
        self.loadingData = false;
        if (response.success) {
          tiyData.tParam.length = [];
          tiyData.tData.productList.length = 0;
          self.$Message.success("保存成功");
          tiyData.tParam.selection.length=0;
          self.webList();
        } else {
          self.$Spin.hide();
          self.$Message.error(response.errorMessage);
        }
      });
  }else{
    self.$apiProduct.batchDeleteProductClassification({
      "productIds": productIds.toString(),
      "selectedClassification": tiyData.tParam.selectedClassification,
      "operation": tiyData.tParam.operation,
    })
      .then(function (response) {
        self.$Spin.hide();
        self.loadingData = false;
        if (response.success) {
          tiyData.tParam.length = [];
          tiyData.tData.productList.length = 0;
          self.$Message.success("删除成功");
          webList(self,tiyData);
        } else {
          self.$Spin.hide();
          self.$Message.error(response.errorMessage);
        }
      });

  }

}
